package com.konglz.publisher.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author konglz
 * @Data 2023/5/13 11:42
 */
@RestController
@Api(tags = "发布订阅-直连模式")
@RequestMapping("/direct")
public class DirectMessageController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * @Description: 简单信息模型案例
     * @return: void
     * @Author: konglz
     * @Date: 2023/5/13
     */
    @GetMapping("/{message}")
    @ApiOperation("direct模式")
    public void direct(@PathVariable String message){
        String exchangeName = "konglz.direct";
        //只发送给routingKey为role的队列
        //rabbitTemplate.convertAndSend(exchangeName,"role",message);

        //只发送给routingKey为user的队列
        rabbitTemplate.convertAndSend(exchangeName,"user",message);
    }
}
